#include <iostream>
#include <signal.h>
#include <unistd.h>
using namespace std;

void handler(int signum)
{
    cout << "Signum : " << signum << endl;
    // 不断获取pending表
    while (true)
    {
        sigset_t pending;
        sigpending(&pending);
        for (int i = 31; i >= 1; i--)
        {
            if (sigismember(&pending, i))
                cout << "1";
            else
                cout << "0";
        }
        cout << endl;
        sleep(1);
    }
    exit(0);
}

int main()
{
    struct sigaction act, oact;
    act.sa_handler = handler;
    sigemptyset(&act.sa_mask);
    // 信号集
    sigaddset(&act.sa_mask, 3);
    sigaddset(&act.sa_mask, 4);
    sigaddset(&act.sa_mask, 5);
    act.sa_flags = 0;

    // 对二号信号进行捕捉
    sigaction(SIGINT, &act, &oact);

    while (true)
    {
        cout << "hello world, " << getpid() << endl;
        sleep(1);
    }

    
    return 0;
}